﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Windows.Forms;

using MouseAndCat.Model;
using Nextensions.GUI;

namespace MouseAndCat
{
    public partial class Main : Form
    {
        //IPEndPoint _endpoint; // = new IPEndPoint(IPAddress.Parse("10.10.5.126"), 8989);
        //UdpClient _cl = new UdpClient();
        Master _master;
        private IntPtr _prevCursor;

        public Main()
        {
            InitializeComponent();

            /*long x = long.MaxValue;
            
            byte[] data = BitConverter.GetBytes(x);
            //Array.Reverse(data);
            StringBuilder bytesString = new StringBuilder(255);

            foreach (byte b in data)
                bytesString.AppendFormat("{0} ", b);

            System.Diagnostics.Debug.WriteLine(x);
            System.Diagnostics.Debug.WriteLine(bytesString);

            IPEndPoint ep = new IPEndPoint(IPAddress.Parse("192.168.1.100"), 8989);
            UdpClient cl = new UdpClient();
            cl.Send(data, data.Length, ep);*/
        }

        private void button1_Click(object sender, EventArgs e)
        {
            InputPersistence.AutoSaveUserInput(this);
            _master = new Master(IPAddress.Parse(cmbIp.Text), Int32.Parse(tPort.Text), (short)Screen.PrimaryScreen.Bounds.Width, (short)Screen.PrimaryScreen.Bounds.Height, Handle);
            //_master.Test(IPAddress.Parse(cmbIp.Text), Int32.Parse(tPort.Text));
            //return;
            _master.Start();
        }

        private void Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_master != null)
                _master.Stop();
        }

        private void Main_Load(object sender, EventArgs e)
        {
            InputPersistence.AutoLoadUserInput(this);
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            throw new NotImplementedException();
            //if(_master == null)
           //     _master = new Master(IPAddress.Parse(cmbIp.Text), Int32.Parse(tPort.Text), (short)Screen.PrimaryScreen.Bounds.Width, Handle);

            //_master.SendMouseEvent(Event.MouseMove, new Point(123, 456));
        }

        private void button2_Click(object sender, EventArgs e)
        {
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
        }
    }
}
